home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Control Common / CEnumConnections.cpp < prev    next >
Text File  |  1996-10-17  |  3KB  |  168 lines

  1. //
  2. #include "ocheaders.h"
  3. #include <LArray.h>
  4. #include "CEnumConnections.h"
  5.  
  6.  
  7. //
  8. //  CEnumConnections::CEnumConnections
  9. //
  10.  
  11. CEnumConnections::CEnumConnections(LArray* ConnectArray)
  12. {
  13.     unsigned long     i;
  14.     CONNECTDATA        ConnectData;
  15.     
  16.     m_RefCount = 0;
  17.     m_Current = 1;
  18.     m_ConnectArray = ConnectArray;
  19.     
  20.     // AddRef all the unknowns in this connect data
  21.     for ( i = 1; i <= m_ConnectArray->GetCount(); i ++ )
  22.     {
  23.         m_ConnectArray->FetchItemAt(i, &ConnectData);
  24.         ConnectData.pUnk->AddRef();
  25.     }
  26. }
  27.  
  28.  
  29. //
  30. //  CEnumConnections::~CEnumConnections
  31. //
  32.  
  33. CEnumConnections::~CEnumConnections(void)
  34. {
  35.     if ( m_ConnectArray )
  36.     {
  37.         unsigned long     i;
  38.         CONNECTDATA*    ConnectData;
  39.     
  40.         for ( i = 1; i <= m_ConnectArray->GetCount(); i ++ )
  41.         {
  42.             ConnectData = (CONNECTDATA*) m_ConnectArray->GetItemPtr(i);
  43.             ConnectData->pUnk->Release();
  44.         }
  45.         
  46.         delete m_ConnectArray;
  47.     }
  48. }
  49.  
  50.  
  51. //
  52. //  CEnumConnections::IUnknown::QueryInterface
  53. //
  54. //  Returns a pointer to the specified interface on a component to which a
  55. //  client currently holds an interface pointer.
  56. //
  57. STDMETHODIMP
  58. CEnumConnections::QueryInterface(REFIID RefID, void** Obj)
  59. {
  60.     void* pv;
  61.  
  62.     if (RefID == IID_IUnknown)
  63.         pv = (void*) this;
  64.     else if (RefID == IID_IEnumConnections )
  65.         pv = (void*)(IEnumConnections*) this;
  66.     else {
  67.         *Obj = NULL;
  68.         return ResultFromScode(E_NOINTERFACE);
  69.     }
  70.  
  71.     *Obj = pv;
  72.     ((IUnknown*) pv)->AddRef();
  73.     return ResultFromScode(S_OK);
  74. }
  75.  
  76.  
  77. //
  78. //  CEnumConnections::IUnknown::AddRef
  79. //
  80. //  Increments the reference count for the calling interface.
  81. //
  82. STDMETHODIMP_(ULONG)
  83. CEnumConnections::AddRef(void)
  84. {
  85.     return ++m_RefCount;
  86. }
  87.  
  88.  
  89. //
  90. //  CEnumConnections::IUnknown::Release
  91. //
  92. //  Decrements the reference count for the calling interface on a object.  If
  93. //  the reference count on the object falls to zero, the object is freed.
  94. //
  95. STDMETHODIMP_(ULONG)
  96. CEnumConnections::Release(void)
  97. {
  98.     if (--m_RefCount != 0)
  99.         return m_RefCount;
  100.  
  101.     delete this;
  102.     return 0;
  103. }
  104.  
  105.  
  106.  
  107.  
  108. //
  109. //  CEnumConnections::IEnumConnections::Next
  110. //
  111. STDMETHODIMP
  112. CEnumConnections::Next(unsigned long NumRequested, 
  113.                 CONNECTDATA* ConnectData,
  114.                 unsigned long* NumReturned)
  115. {
  116.     unsigned long     Returned = 0;
  117.     unsigned long    RemainingRequests = NumRequested;
  118.     
  119.     while ( m_Current <= m_ConnectArray->GetCount() && RemainingRequests > 0 )
  120.     {
  121.         // Copy the item to the CONNECTDATA and addref
  122.         m_ConnectArray->FetchItemAt(m_Current, ConnectData);
  123.         ConnectData->pUnk->AddRef();
  124.         
  125.         // Move to the next item in the given CONNECTDATA array
  126.         ConnectData++;
  127.         
  128.         // One more returned, one less requested
  129.         Returned ++;
  130.         RemainingRequests --;
  131.         
  132.         // Next item please
  133.         m_Current++;
  134.     }
  135.     
  136.     // if the client is interested, pass this info back
  137.     if ( NumReturned )
  138.         (*NumReturned) = Returned;
  139.     
  140.     // Set the correct return value
  141.     if ( Returned == NumRequested )
  142.         return ResultFromScode(S_OK);
  143.     else
  144.         return ResultFromScode(S_FALSE);
  145. }
  146.  
  147.  
  148. //
  149. //  CEnumConnections::IEnumConnections::Skip
  150. //
  151. STDMETHODIMP
  152. CEnumConnections::Skip(unsigned long NumSkip)
  153. {
  154. #pragma unused (NumSkip)
  155.     return E_NOTIMPL;
  156. }
  157.  
  158.  
  159. //
  160. //  CEnumConnections::IEnumConnections::Clone
  161. //
  162. STDMETHODIMP
  163. CEnumConnections::Clone(IEnumConnections** Enum)
  164. {
  165. #pragma unused (Enum)
  166.     return E_NOTIMPL;
  167. }
  168.